package com.huawei.chengdu.meetingdemo.util;

import com.huawei.chengdu.meetingdemo.presenter.RecordBookPresenter;

public class AppContext {
    private static final String TAG = AppContext.class.getSimpleName();

    private static volatile AppContext appInstance = null;

    /**
     * 记录本的service
     */
    public RecordBookPresenter rbServ;

    /**
     * 非UI线程处理UI相关的操作的handler
     */
    public GlobalHandler globalHandler;

    /**
     * 获取AppContext的单例
     *
     * @return AppContext的实例
     */
    public static AppContext instance() {
        // 如果为空或是没有实例化完成，则等待
        if (appInstance == null) {
            synchronized (AppContext.class) {
                if (appInstance == null) {
                    LogUtil.debug(TAG + " appContext init");
                    appInstance = new AppContext();
                    appInstance.init();
                }
            }
        }

        return appInstance;
    }

    private AppContext() {}

    private void init() {
        // 注册service层的类
        registService();
        globalHandler = GlobalHandler.getInstance();
    }

    /**
     * 注册service层的各个类
     */
    private void registService() {
        // 记录本的服务类
        rbServ = new RecordBookPresenter();
    }
}
